"use client";
import { FC, PropsWithChildren, useState } from "react";
import { useRouter } from "@/i18n";
import HeaderBack from "@/components/HeaderBack";
import GoogleCom from "../login/component/GoogleCom";
import FromCom from "../login/component/FromCom";
import DomainFooter from "@/components/DomainFooter";
import '../login/page.scss'
import {getRegisterApi} from "@/api/user";
import { Toast } from 'antd-mobile'
import { useTranslations } from "next-intl";

interface Props {}

const Register: FC<PropsWithChildren<Props>> = () => {
    const t = useTranslations("LoginPage");
    const router:any = useRouter()
    const [msgError, setMsgError] = useState('')
    const registerRequest = async ({userPhone, pwd}: any) => {
        let params = {user_phone: userPhone, pwd, code: '123456'}
        let { code, msg } = await getRegisterApi(params)
        if(code == 200) {
            Toast.show({ icon: 'success', content: t("registerSuc"), maskClickable: false })
            setTimeout(() => {
                router.replace('/login')
            }, 1000)
        } else {
            setMsgError(msg)
        }
    }
    return (
        <div className="register-box">
            <HeaderBack />
            <GoogleCom title={t("registerGoogletitle")} text={t("registerGoogletext")}/>
            <FromCom type="register" callbackFun={registerRequest} msgError={msgError}/>
            <DomainFooter />
        </div>
    );
};

export default Register;
